<?php
import( 'de.ceus-media.framework.krypton.core.Logic' );
import( 'classes.model.Topic' );
import( 'classes.model.Attachment' );
//import( 'de.ceus-media.framework.krypton.core.database.StatementBuilder' );
/**
 *	Logic of Licencee, Locations and Companies.
 *	@package		mv2.logic
 *	@extends		Framework_Krypton_Core_Logic
 *	@author			Christian Würker <Christian.Wuerker@CeuS-Media.de>
 *	@author			David Seebacher <dseebacher@gmail.com>
 *	@since			13.03.2007
 *	@version		0.1
 */
/**
 *	Logic of Licencee, Locations and Companies.
 *	@package		mv2.logic
 *	@extends		Framework_Krypton_Core_Logic
 *	@author			Christian Würker <Christian.Wuerker@CeuS-Media.de>
 *	@author			David Seebacher <dseebacher@gmail.com>
 *	@since			13.03.2007
 *	@version		0.1
 */
class Logic_Attachment extends Framework_Krypton_Core_Logic
{
	function addAttachment( $uri, $title = false, $description = false )
	{
		$case	= new Model_Attachment();
		$data	= array(
			'uri'		=> $uri,
			);
		if( $title )
			$data['title']	= $title;
		if( $description )
			$data['description']	= $description;
		return $case->insert( $data, false );
	}

/*	static function getAttachmentList( $topicId, $filters = array(), $orders = array() )
	{
		$model	= new Model_Attachment();
		$conditions	= array_merge( array( 'topic_id' => $topicId ), $filters );
		return $model->find( array(), $conditions, $orders );
	}
*/
	static function getAttachmentData( $attachmentId )
	{
		$model	= new Model_Attachment( $attachmentId );
		$data	= $model->get();
		if( !$data )
			throw new Framework_Krypton_Exception_Logic( 'invalid_attachment_id' );
		return $data;
	}
	
	static function getAttachmentDescription( $attachmentId )
	{
		$data	= self::getAttachmentData( $attachmentId );
		return $data['description'];
	}

	static function getAttachmentTitle( $attachmentId )
	{
		$data	= self::getAttachmentData( $attachmentId );
		return $data['title'];
	}

	static function getAttachmentUri( $attachmentId )
	{
		$data	= self::getAttachmentData( $attachmentId );
		return $data['uri'];
	}
}
?>
